package
{
	import com.utils.actionList.ActionListEvent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.ProgressEvent;
	import flash.geom.Matrix;
	import flash.net.URLLoader;
	import flash.utils.ByteArray;
	
	import game.physic.Input;
	import game.physic.Physic;
	
	public class Model extends EventDispatcher
	{
		public var screenWidth:Number  = 760;
		public var screenHeight:Number = 460;

		protected var _configXML:XML;
		
		// TIMES  /////////////////////////////////////////////////////////////////////////////
		public static const STATE_TIMER_READY:int = 0;
		public static const STATE_TIMER_BUSY:int  = 1;
		
		public var timerState:int  = 0;
		public var rowChangeTime:int  = 10000; // mili secs 10 sec
		public var loadConfigTime:int = 900000; // mili secs 15 mins

		public var gameDificulty:int = 1;
		public var gameTime:Number   = 0;  // milisecs
		public var gameTimeTicks:int = 0;  // frames
		public var gameScore:int     = 0;
		public var userLifes:int     = 3;
		public var userHealth:Number = 1.0;
		
		public var powerLevel:Number = 0.0;
		public var powerLevelSpeed:Number;
		
		public var stripSpeed:Number         = 5.0; // velocidad de movimiento de la banda
		public var itemCreationSpeed:Number  = 40; // milisecs 
		public var itemCreationGap:Number    = 70; // pixels between items
		public var enemyCreationSpeed:Number = 80; // milisecs 
		
		// PHYSICS  /////////////////////////////////////////////////////////////////////////////
		public var physic:Physic;
		public var input:Input;
		
		// EVENTS /////////////////////////////////////////////////////////////////////////////
		public static const EVT_ERROR_NO_CONFIG_FILE:String    = "EVT_ERROR_NO_CONFIG_FILE";
		
		public function Model(target:IEventDispatcher=null)
		{
			super(target);
			
		}
		
		// LOGIC /////////////////////////////////////////////////////////////////////////////
		public function resetGameVariables():void
		{
			gameDificulty = 1;
			gameTime      = 0.0;
			gameTimeTicks = 0;
			gameScore     = 0;
			userLifes     = 3; // cambia con el xml
			userHealth    = 1.0;
			powerLevel    = 0.0;
			powerLevelSpeed = 0.05; // from xml
			
			dispatchEvent(new ActionListEvent(ActionListEvent.EVT_ACTION_LIST_ITEM_COMPLETE));
		}
		
		public function updateGameTime():void
		{
			gameTime += 100.0/3.0;
			gameTimeTicks += 1;
		}
		
		// PHYSICS /////////////////////////////////////////////////////////////////////////////
		public function setupPhysics():void
		{
			physic = new Physic();
			
			input = new Input(physic.m_sprite);
			
			physic.Update();
			Input.update();
			dispatchEvent(new ActionListEvent(ActionListEvent.EVT_ACTION_LIST_ITEM_COMPLETE));
		}
  		
		// GETTERS & SETTERS  /////////////////////////////////////////////////////////////////////////
		public function get configXML():XML { return _configXML; }
		public function set configXML(val:XML ):void { _configXML = val; }
	}
}